package design.pattern.Lu12StrategyPattern;

/**
 * @program JavaBase
 * @description: 策略模式
 * @author: zhanglu
 * @create: 2020-04-09 13:48:00
 */
public class StrategyPattern {

    public static void main(String[] args) {
        Context context = new Context(new ConcreteStrategy01());
        context.todo();
    }

}

interface Strategy{
    void todo();
}

class ConcreteStrategy01 implements Strategy{

    @Override
    public void todo() {
        System.out.println("做第一件事");
    }
}

class ConcreteStrategy02 implements Strategy{

    @Override
    public void todo() {
        System.out.println("做第二件事");
    }
}

class Context{

    private Strategy strategy;

    public Context(Strategy strategy){
        this.strategy = strategy;
    }

    public void todo(){
        this.strategy.todo();
    }

}